/**
 * 
 */
package com.woodbird.legend.configuration;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * @author woodbird
 * @version 2010-3-1
 */
public class Configuration {

	private Map<Object, Object> conf = new HashMap<Object, Object>();

	private static Configuration instance;

	private Configuration() {
		try {
			Properties p = new Properties();
			InputStream in = Configuration.class.getResourceAsStream("legend-default.properties");
			p.load(in);
			for (Object key : p.keySet()) {
				conf.put(key, p.get(key));
			}
			in = Configuration.class.getClassLoader().getResourceAsStream("legend.properties");
			if (null == in) {
				return;
			}
			p.load(in);
			for (Object key : p.keySet()) {
				conf.put(key, p.get(key));
			}
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	public static Configuration loadConfiguration() {
		if (null == instance) {
			instance = new Configuration();
		}
		return instance;

	}

	public Object getProperty(Object key) {
		return conf.get(key);
	}

	public void setProperty(Object key, Object value) {
		conf.put(key, value);
	}
	
	public boolean isNeedInstrument(String className){
		return true;
	}
}
